using System.Windows.Forms;

namespace JN.Utility
{
    public class MessageDialog
    {
        #region Fields

        private static string _caption = GlobalFunction.GetLanguageText("Prompt Message");
        private static IWin32Window _fullForm = null;
        private static IWin32Window _mainForm = null;

        #endregion

        static MessageDialog()
        {
        }

        public static void ConfigOwnerWindow(IWin32Window fullForm, IWin32Window mainForm)
        {
            _fullForm = fullForm;
            _mainForm = mainForm;
        }

        #region Methods

        private static IWin32Window GetOwnerWindow()
        { 
            IWin32Window owner = null;
            if ( _fullForm != null && Win32API.IsWindow(_fullForm.Handle))
            {
                owner = _fullForm;
            }
            else if ( _mainForm != null && Win32API.IsWindow(_mainForm.Handle))
            {
                owner = _mainForm;
            }
            return owner; 
        }


        public static DialogResult Show(string text, params object[] paras)
        {
            text = GetLanguageText(text, paras);
            return MessageBox.Show(GetOwnerWindow(), text, _caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        public static DialogResult Error(string text, params object[] paras)
        {
            text = GetLanguageText(text, paras);
            return MessageBox.Show(GetOwnerWindow(), text, _caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
        }

        public static DialogResult Warning(string text, params object[] paras)
        {
            text = GetLanguageText(text, paras);
            return MessageBox.Show(GetOwnerWindow(), text, _caption, MessageBoxButtons.OK, MessageBoxIcon.Warning);
        }

        public static DialogResult Question(string text, params object[] paras)
        {
            text = GetLanguageText(text, paras);
            return MessageBox.Show(GetOwnerWindow(), text, _caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
        }

        public static DialogResult Show(IWin32Window owner, string text, params object[] paras)
        {
            text = GetLanguageText(text, paras);
            return MessageBox.Show(owner, text, _caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        public static DialogResult Show(string text, MessageBoxButtons buttons, params object[] paras)
        {
            text = GetLanguageText(text, paras);
            return MessageBox.Show(GetOwnerWindow(), text, _caption, buttons, MessageBoxIcon.Information);
        }

        public static DialogResult Show(string text, MessageBoxButtons buttons, MessageBoxIcon icon, params object[] paras)
        {
            text = GetLanguageText(text, paras);
            return MessageBox.Show(GetOwnerWindow(), text, _caption, buttons, icon);
        }

        public static DialogResult Show(IWin32Window owner, string text, MessageBoxButtons buttons, params object[] paras)
        {
            text = GetLanguageText(text, paras);
            return MessageBox.Show(owner, text, _caption, buttons, MessageBoxIcon.Information);
        }

        public static DialogResult Show(string text, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, params object[] paras)
        {
            text = GetLanguageText(text, paras);
            return MessageBox.Show(GetOwnerWindow(), text, _caption, buttons, icon, defaultButton);
        }

        public static DialogResult Show(IWin32Window owner, string text, MessageBoxButtons buttons, MessageBoxIcon icon, params object[] paras)
        {
            text = GetLanguageText(text, paras);
            return MessageBox.Show(owner, text, _caption, buttons, icon);
        }

        public static DialogResult Show(string text, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options, params object[] paras)
        {
            text = GetLanguageText(text, paras);
            return MessageBox.Show(GetOwnerWindow(), text, _caption, buttons, icon, defaultButton, options);
        }

        public static DialogResult Show(IWin32Window owner, string text, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, params object[] paras)
        {
            text = GetLanguageText(text, paras);
            return MessageBox.Show(owner, text, _caption, buttons, icon, defaultButton);
        }

        public static DialogResult Show(IWin32Window owner, string text, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options, params object[] paras)
        {
            text = GetLanguageText(text, paras);
            return MessageBox.Show(owner, text, _caption, buttons, icon, defaultButton, options);
        }

        private static string GetLanguageText(string text, params object[] paras)
        {
            return GlobalFunction.GetLanguageText(text, paras);
        }

        #endregion
    }
}
